﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Runtime.InteropServices.Automation;
using Ivvy_Silverlight.i7SR;

namespace Ivvy_Silverlight.Ivvy
{
    public class ExportToWord
    {
        public string TemplateFileName = "http://tritusco.com/JAGwork/ifund/screenshots/AppointmentTemplate.docx";
        public  const string FontBoldS = "BoldF";
        public const string NewLineS = "NewLine";
        private const int FontBold = 9999998;

        public bool ExportToWord_withTemplate(Dictionary<string, string> WordsForReplaceInTemplate)
        {   
            if (!AutomationFactory.IsAvailable)
                return false;            
            dynamic word = AutomationFactory.CreateObject("Word.Application");
            dynamic doc = word.Documents.Open(TemplateFileName);
            word.Selection.Find.ClearFormatting();
            word.Selection.Find.Replacement.ClearFormatting();
            foreach (KeyValuePair<string, string> kvp in WordsForReplaceInTemplate)
                word.Selection.Find.Execute(kvp.Key, true, false, false, false, false, true, 1, false, kvp.Value, 2);
            
            word.visible = true;
            

            return true;
        }//public bool ExportToWord_withTemplate(Dictionary<string, string> WordsForReplaceInTemplate)
            

        public bool ExportToWord_SpecialList(List<string> ListForExport)
        {
            if (!AutomationFactory.IsAvailable)
                return false;
            dynamic word = AutomationFactory.CreateObject("Word.Application");
            dynamic doc = word.Documents.Add();
            foreach (var CurrentListForExport in ListForExport)
                if (CurrentListForExport == NewLineS)
                    word.Selection.TypeParagraph();
                else if (CurrentListForExport == FontBoldS)
                    word.Selection.Font.Bold = FontBold;
                else
                    word.Selection.TypeText(CurrentListForExport);
            word.visible = true;
            return true;
        }//public bool ExportToWord_SpecialList(List<string> ListForExport)

        public bool ExportToWord_CalendarItem(i_CalendarItem CalendarItemForExportW)
        {
            if (!AutomationFactory.IsAvailable)
                return false;
            dynamic word = AutomationFactory.CreateObject("Word.Application");
            dynamic doc = word.Documents.Add();
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText("CalendarItem ID: " );
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText( CalendarItemForExportW.CalendarItem_ID.ToString());
            word.Selection.TypeParagraph();
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText("Entry_Name:" );
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText(CalendarItemForExportW.Entry_Name);            
            word.Selection.TypeParagraph();
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText("Start date: " );
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText(CalendarItemForExportW.Start_Date.ToString());
            word.Selection.TypeParagraph();
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText("End date: " );
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText(CalendarItemForExportW.End_Date.ToString());
            word.Selection.TypeParagraph();
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText("Name: ");
            word.Selection.Font.Bold = FontBold;
            word.Selection.TypeText(CalendarItemForExportW.Salutation + " " + CalendarItemForExportW.FirstName + " " + CalendarItemForExportW.LastName);
            word.Selection.TypeParagraph();
            word.visible = true;
            return true;
        }//public bool ExportToWord_CalendarItem(CalendarItem CalendarItemForExportW)
    }//public class ExportToWord
}//namespace Ivvy_Silverlight.Ivvy
